'use strict';

module.exports = {
	/**
	 * 获取用户充值数据接口
	 * @url api/pub/data/analyzer/getRecharge 报表分析使用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();
		const dbcmd = db.command;
		
		let { 
			data = {}, userInfo, util, filterResponse, originalParam
		 } = event;
		let { 
			} = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let dbName = "report_channel_hour"; // 表名
        if (userInfo.username == "admin") {
			// if(ad_id){
			// 	res = await vk.baseDao.getTableData({
			// 		dbName,
			// 		data,
			// 		whereJson: { // 条件
			// 			ad_id: ad_id
			// 		},
			// 		sortArr: [{ "name":"date_time", "type":"desc" }]
			// 	});
			// }else{
				res = await vk.baseDao.getTableData({
					dbName,
					data,
					whereJson: { // 条件
					},
					sortArr: [{ "name":"date_time", "type":"desc" }]
				});
			//}
        	
        	// 业务逻辑结束-----------------------------------------------------------
        	return res;
        }
        if (userInfo.role.includes("middleman")) {
        	res = await vk.baseDao.getTableData({
        		dbName,
        		data,
        		whereJson: { // 条件
        		    middleman_id: userInfo._id
        		},
				sortArr: [{ "name":"date_time", "type":"desc" }]
        	});
        	// 业务逻辑结束-----------------------------------------------------------
        	return res;
        }
        if (userInfo.role.includes("agent")) {
        	res = await vk.baseDao.getTableData({
        		dbName,
        		data,
        		whereJson: { // 条件
        		    agent_id: userInfo._id
        		},
				sortArr: [{ "name":"date_time", "type":"desc" }]
        	});
        	// 业务逻辑结束-----------------------------------------------------------
        	return res;
        }
	}
}